var divs = new Array;
var id = new Array;
var name = new Array;
var address = new Array;
var city = new Array;
var region = new Array;
var country = new Array;
function getVenues() {
	if (typeof divs[0] == 'undefined' && divs[0] == null) {
		$.get('RecentVenuesServlet', function(responseJson) {    // Execute Ajax GET request on URL of "someservlet" and execute the following function with Ajax response JSON...
			$("div[id='recentvenues']").empty();
			$.each(responseJson, function(index, item) {
				$.each(item, function(index, item) {
					switch(index) {
					case "id":
						id.push(item);
						break;
					case "name":
						name.push(item);
						break;
					case "address":
						address.push(item);
						break;
					case "city":
						city.push(item);
						break;
					case "region":
						region.push(item);
						break;
					case "country":
						country.push(item);
						break;
					}
				});
			});
			if (typeof id[0] !== 'undefined' && id[0] !== null)
				for (var i = 0; i < id.length; i++)
					divs += '<div><p style="font-size: 14px;"><a href="#" data-dismiss="modal" onClick="fillVenue(' + id[i] +')">' + name[i] + '</a></p><p>' + address[i] + ' - ' + city[i] + ', ' + region[i] + ', ' + country[i] + '</p></div>';
			else if (id.empty())
				divs += '<div><p style="font-size: 16px; font-style: italic;>No recent venues to display!</p></div>';
			$("div[id='recentvenues']").html(divs);
		});
	}
}

function fillVenue(idx) {
	var index = jQuery.inArray(idx, id);
	document.getElementById("venueid").value = idx;
	document.getElementById("venue").value = name[index];
	document.getElementById("venue").disabled = true;
	document.getElementById("venueaddress").value = address[index];
	document.getElementById("venueaddress").disabled = true;
	document.getElementById("country").value = country[index];
	document.getElementById("country").disabled = true;
	reg = [];
	reg += '<option selected="selected" value="' + region[index] + '">' + region[index] + '</option>';
	$("select[id='region']").html(reg);
	document.getElementById("region").disabled = true;
	cit = [];
	cit += '<option selected="selected" value="' + city[index] + '">' + city[index] + '</option>';
	$("select[id='city']").html(cit);
	document.getElementById("city").disabled = true;
}
function clearVenue() {
	document.getElementById("venue").value = null;
	document.getElementById("venue").disabled = false;
	document.getElementById("venueaddress").value = null;
	document.getElementById("venueaddress").disabled = false;
	document.getElementById("country").value = null;
	document.getElementById("country").disabled = false;
	document.getElementById("country").value = "Select A Country";
	document.getElementById("region").value = "Select A Region";
	document.getElementById("region").disabled = false;
	document.getElementById("country").value = null;
	document.getElementById("city").disabled = false;
	document.getElementById("city").value = "Select A City";
}